<?php
namespace App\Services\Admin;

use App\Repositories\Admin\JobRepository;

class JobService
{
    private $service;

    public function __construct()
    {
        $this->service = new JobRepository();
    }

    public function getIndex()
    {
        return $this->service->getIndexList();
    }

    public function getIndexList()
    {
        $models = $this->service->getJobsByCate();
        foreach ($models as $model) {
            $cateName = $model->cate==1 ? '工厂' : '公司';
            $model->name = $cateName.'--'.$model->name;
            $model->subJobs = $this->service->getJobsByPid($model->cate,$model->id);
        }
        return $models;
    }

    public function getJobs($cate)
    {
//        return $this->service->getJobsByCate($cate);
        $models = $this->service->getJobsByCate($cate);
        foreach ($models as $model) {
            $model->subJobs = $this->service->getJobsByPid($cate,$model->id);
        }
        return $models;
    }

    public function getParents()
    {
        $models = $this->service->getParentList();
        $dataArr = array('所有');
        if (!count($models)) { return $dataArr; }
        foreach ($models as $model) {
            $cateName = $model->cate==1 ? '工厂' : '公司';
            $model->name = $cateName.'--'.$model->name;
            $dataArr[$model->id] = $model->name;
        }
        return $dataArr;
    }

    public function add($data)
    {
        return $this->service->setAdd($data);
    }

    public function modify($data,$id)
    {
        return $this->service->setModify($data,$id);
    }

    public function getOne($id)
    {
        return $this->service->getShowOne($id);
    }
}